<?php
/**
 * Controller_Admin_Statistic
 *
 * Класс Controller_Admin_Statistic отвечает за обработку страниц со статистикой
 *
 * @author Mike
 */
class Controller_Admin_Statistic extends Controller_Admin {

	/**
	 * Выбор действия по URL
	 *
	 */
	public function action() {
		if(!User_Seance::isAdmin()) throw new Exception('', 403);
		switch ($this->arrRequest[2]) {
			case '':
				$this->actionMainStat();
			  	break;
			default: throw new Exception('', 404);
		}
	}

	/**
	 * Выводит страницу основной статистики
	 * 
	 */
	public function actionMainStat() {
		$objDB = Service_Database::instanse();
		$objUser = new User_User();
		$objTeam = new Team();
		$objTournament = new Tournament();
		
		$stmt = "SELECT COUNT(`feedback`.`ID_feedback`) FROM `feedback` WHERE `feedback`.`is_read` IS NULL";
		$feedbacks = $objDB->selectOneValue($stmt);
		
		$arrStat = array(
				'users' => $objUser->count(),
				'teams' => $objTeam->count(),
				'tours' => $objTournament->count(),
				'users_today' => $objUser->count("DATE_FORMAT(`created_at`,'%Y-%m-%d') = '" . gmdate("Y-m-d", time()) . "'"),
				'teams_today' => $objTeam->count("DATE_FORMAT(`created_at`,'%Y-%m-%d') = '" . gmdate("Y-m-d", time()) . "'"),
				'tours_today' => $objTournament->count("DATE_FORMAT(`created_at`,'%Y-%m-%d') = '" . gmdate("Y-m-d", time()) . "'"),
				'feedbacks' => $feedbacks
				);
		
		$this->bodyAttr = "cms main-stat";
	  	$this->title = $this->pageHead = 'Основная статистика';
	  
	  	$this->showHeader();
	   		View_Statistic::showStatMain($arrStat);
		$this->showFooter();
	}
}
?>